﻿using ZoneLineNew.Core;
using FreeSql;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZoneLineNew.Services.DB
{
    public class FreeSqlMainContext : IFreeSqlMainContext
    {
        //本地数据库IP
        private const string _DBStr = "server=localhost;port=3306;User Id=root;password=root;Database=cks2407;charset=utf8; SslMode=none";
        //后减数据库IP
        //public static string DBStr => ConfigurationUtil.GetConfiguration(Convert.ToString, () => "server=172.20.23.175;port=3306;User Id=root;password=root;Database=cks2407;charset=utf8; SslMode=none");
        //前减数据库IP
        //public static string DBStr => ConfigurationUtil.GetConfiguration(Convert.ToString, () => "server=172.20.23.128;port=3306;User Id=root;password=root;Database=cks2407;charset=utf8; SslMode=none");

        public IFreeSql DbContext { get; private set; }

        public FreeSqlMainContext() {
            DbContext = new FreeSqlBuilder()
                            .UseConnectionString(DataType.MySql, _DBStr)
                            .UseAutoSyncStructure(true)
                            .UseMonitorCommand((cmd) => {
#if DEBUG
                                LogManager.Debug(cmd.CommandText);
#endif
                            }).Build();
        }
    }
}
